package com.moji.java_moji.controller;

import com.moji.java_moji.entity.user;
import com.moji.java_moji.service.UserSerice;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;

@RestController
public class appStateController {
    @Resource
    UserSerice userserice = null;

    @RequestMapping("/login")
    public HashMap<String, Object> login(@RequestBody HashMap<String,String> map, HttpSession session){
        HashMap<String,Object> respMap = userserice.login(map);
        String status = (String) respMap.get("status");
        user data = (user) respMap.get("data");
        if (status == "0") {
            session.setAttribute("id", data.getId());
        }
        return respMap;
    }

    @RequestMapping("/register")
    public HashMap<String,Object> register(@RequestBody HashMap<String,String> map){
        System.out.println(map);
        HashMap<String, Object> respMap = new HashMap<String, Object>();
        user u = new user();
        respMap.put("String","a");
        respMap.put("islogin",true);
        respMap.put("user",u);
        return respMap;
    }
}
